package com.example.dormitorysystem.controller;


import com.example.dormitorysystem.common.aop.OperationLogAnnotation;
import com.example.dormitorysystem.entity.Beds;
import com.example.dormitorysystem.entity.Buildings;
import com.example.dormitorysystem.entity.Rooms;
import com.example.dormitorysystem.entity.pojo.BedsOutput;
import com.example.dormitorysystem.service.BedsService;
import com.example.dormitorysystem.service.BuildingsService;
import com.example.dormitorysystem.service.RoomsService;
import com.example.dormitorysystem.utils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 吉吉王国组
 * @since 2022-11-26
 */
@RestController
@RequestMapping("")
@Component
public class BedsController {

    //将所有相关的impl都注入
    @Resource
    private BedsService bedsService;

    @Resource
    private BuildingsService buildingsService;

    @Resource
    private RoomsService roomsService;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 这里做了简单的修改，只显示总的可以查询的数量
     * 应该没有人会在意具体的床位的吧
     * @param request
     * @return
     */

    @GetMapping("/room/empty")
    @OperationLogAnnotation(operModul = "床位信息模块", operType = "BedInfo", operDesc = "获取床位信息")
    //输出完整的表单
    public Response getBedInfo( HttpServletRequest request) {

        //从Redis中获取数据，需要获取每个宿舍楼的全部信息
        HashMap<String, Object> res = new HashMap<>();
        for(int i = 1;i<6;++i){
            int male_four_man_room = Integer.parseInt(stringRedisTemplate.opsForValue().get(i + "male_four_man_room"));
            int male_six_man_room = Integer.parseInt(stringRedisTemplate.opsForValue().get(i + "male_six_man_room"));
            int female_four_man_room = Integer.parseInt(stringRedisTemplate.opsForValue().get(i + "female_four_man_room"));
            int female_six_man_room = Integer.parseInt(stringRedisTemplate.opsForValue().get(i + "female_six_man_room"));
            int male_random_num = Integer.parseInt(stringRedisTemplate.opsForValue().get(i + "male_random_num"));
            int female_random_num = Integer.parseInt(stringRedisTemplate.opsForValue().get(i + "female_random_num"));

            res.put(i + "male_four_man_room", male_four_man_room);
            res.put(i + "male_six_man_room", male_six_man_room);
            res.put(i + "female_four_man_room", female_four_man_room);
            res.put(i + "female_six_man_room", female_six_man_room);
            res.put(i + "male_random_num", male_random_num);
            res.put(i + "female_random_num", female_random_num);

        }

            return Response.success().data(res);
    }
}


